package com.cskaoyan.proxy;

import com.cskaoyan.bean.JingTian;
import net.sf.cglib.core.DebuggingClassWriter;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.InvocationHandler;

import java.lang.reflect.Method;

/**
 * @author stone
 * @date 2021/12/24 15:05
 */
public class ExecuteCglibProxy {

    public static void main(String[] args) {
        //字节码文件也是默认不保存 → value写的是路径
        // 和委托类相同的包目录
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "D:\\WorkSpace\\j36_workspace\\codes\\day03-proxy-spring\\demo4-proxy-save");
        JingTian jingTian = new JingTian();
        JingTian proxy = (JingTian) Enhancer.create(JingTian.class, new InvocationHandler() {
            @Override
            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                method.invoke(jingTian, objects);
                System.out.println("卤蛋和烤肠");
                return null;
            }
        });
        proxy.buyFood("可口可乐");
    }
}
